//
//  FollowTableView.m
//  KingSelected
//
//  Created by 杨鹏 on 2023/10/31.
//

#import "FollowTableView.h"

@implementation FollowTableView

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
    if (self = [super initWithFrame:frame style:style]) {
        self.backgroundColor = [UIColor whiteColor];
        self.showsVerticalScrollIndicator = NO;
        self.delegate = self;
        self.dataSource = self;
        if (@available(iOS 11.0, *)) {
            self.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
    }
    return self;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.modelArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    FollowTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FollowTableViewCell"];
    if (!cell) {
        cell = [[FollowTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"FollowTableViewCell"];
    }
    cell.model = self.modelArr[indexPath.row];
    @weakify(self)
    [cell setFollowBtnBlock:^(UserModel * _Nonnull model) {
        @strongify(self)
        if (self.followBtnBlock) {
            self.followBtnBlock(model);
        }
    }];
    [cell setTopBtnBlock:^(UserModel * _Nonnull model) {
       @strongify(self)
        if (self.topBtnBlock) {
            self.topBtnBlock(model);
        }
    }];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 90;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self.subject sendNext:indexPath];
}

- (NSMutableArray *)modelArr {
    if (!_modelArr) {
        _modelArr = [NSMutableArray array];
    }
    return _modelArr;
}

- (RACSubject *)subject {
    if (!_subject) {
        _subject = [RACSubject subject];
    }
    return _subject;
}

@end
